/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.manager;

import br.com.foxline.model.Groups;
import br.com.foxline.model.Users;
import br.com.foxline.service.GroupsService;
import br.com.foxline.service.UserService;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.primefaces.model.DualListModel;

/**
 *
 * @author ely
 */
@ManagedBean
@ViewScoped
public class ManagerUser {

    @EJB
    UserService userService;
    @EJB
    GroupsService groupService;
    
    private Users users;
    private String confirm;
    private DualListModel<Groups> dualGrupo;
    private List<Groups> gruposSelec;

    public ManagerUser() {
    }

    @PostConstruct
    public void init() {
        users = new Users();
        confirm = new String();
        gruposSelec = new ArrayList<Groups>();
        dualGrupo = new DualListModel<Groups>(groupService.findAll(), gruposSelec);

    }

    public void create() {
        users.setGroups(dualGrupo.getTarget());
        userService.saveUser(confirm, users);
        users = new Users();
    }

    public Users getUsers() {
        return users;
    }

    public void setUsers(Users users) {
        this.users = users;
    }

    public String getConfirm() {
        return confirm;
    }

    public void setConfirm(String confirm) {
        this.confirm = confirm;
    }

    public DualListModel<Groups> getDualGrupo() {
        dualGrupo = new DualListModel<Groups>(groupService.findAll(), gruposSelec);
        return dualGrupo;
    }

    public void setDualGrupo(DualListModel<Groups> dualGrupo) {
        this.dualGrupo = dualGrupo;
    }
}
